package net.cheyo.util;

public class StringUtil
{
    public static boolean isIpAddr(String ip)
    {
        String strIp = ip;
        while (strIp.startsWith(" "))
        {
            strIp = strIp.substring(1, strIp.length()).trim();
        }
        while (strIp.endsWith(" "))
        {
            strIp = strIp.substring(0, strIp.length() - 1).trim();
        }

        boolean result = false;
        if (strIp.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"))
        {
            String s[] = strIp.split("\\.");
            if ((Integer.parseInt(s[0]) < 255)
                    && (Integer.parseInt(s[1]) < 255)
                    && (Integer.parseInt(s[2]) < 255)
                    && (Integer.parseInt(s[3]) < 255))
            {
                result = true;
            }
        }
        
        return result;
    }
    
    public static boolean isMobileNum(String mobileNum)
    {
        if (null == mobileNum)
        {
            return false;
        }
        
        if (11 != mobileNum.length())
        {
            return false;
        }
        
        if (!mobileNum.matches("\\d{11,11}"))
        {
            return false; 
        }
        
        return true;
    }
    
    public static boolean isIdCard(String idCard)
    {
        if (null == idCard)
        {
            return false;
        }
        
        if ((15 != idCard.length()) && (18 != idCard.length()))
        {
            return false;
        }
        
        //todo
//        if (!idCard.matches("\\d{15,15}"))
//        {
//            return false; 
//        }
        
        return true;
    }
}
